package com.caijg.controller.user;

import com.caijg.domain.dto.UserMessageDTO;
import com.caijg.domain.vo.Result;
import com.caijg.service.IChatService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Publisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 对话表 前端控制器
 * </p>
 *
 * @author caijg
 * @since 2024-12-26
 */
@RestController
@RequestMapping("/user/chat")
@Tag(name = "AI助手模块")
@Slf4j
public class UserChatController {

    @Autowired
    private IChatService chatService;

    @Operation(summary = "AI对话")
    @PostMapping
    public Result chat(@RequestBody UserMessageDTO userMessageDTO) {
        return chatService.chat(userMessageDTO);
    }

    @Operation(summary = "历史对话列表查询")
    @GetMapping("/history")
    public Result history(String userId) {
        log.info("历史对话列表查询，userId：{}", userId);
        return chatService.history(userId);
    }

    @Operation(summary = "用户查询某次对话记录")
    @GetMapping("/messages")
    public Result messages(String sessionId) {
        log.info("具体的一个对话所有消息查询，sessionId：{}", sessionId);
        return chatService.messages(sessionId);
    }

    @Operation(summary = "用户删除对话")
    @GetMapping("/delete")
    public Result delete(String sessionId) {
        log.info("删除一个对话，sessionId：{}", sessionId);
        return chatService.delete(sessionId);
    }
}
